package com.soft.idc.common.control;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.soft.idc.common.model.IdcOrg;
import com.soft.idc.common.model.IdcRole;
import com.soft.idc.common.model.IdcUser;
import com.soft.idc.common.service.IdcMenuService;

@Before(AuthInterceptor.class)
public class IndexController extends Controller {

	public void index() {
		IdcOrg org = (IdcOrg)this.getSessionAttr("SYS_USER_ORG");
		IdcUser user = (IdcUser)this.getSessionAttr("SYS_USER");
		IdcRole role = (IdcRole)this.getSessionAttr("SYS_USER_ROLE");
		this.setAttr("realname", user.getRealname());
		this.setAttr("rolename", role.getRolename());
		this.setAttr("orgname", org.getName());
		this.renderJsp("/index.jsp");
	}

	public void loadMenu() {
		IdcUser user = (IdcUser)this.getSessionAttr("SYS_USER");
		String userId = user.getUserId().toString();
		List<Record> menuList = IdcMenuService.loadMenu(userId);
		this.renderJson(menuList);
	}

}
